
const app = getApp()
Page({

	data: {
		page:1,
		keywords:null,
		type:1,
		totalPage:1,
		activeTab:0,
		dataList:[]
	},
	onLoad(options) {
		this.getList()
	},
	tabChange(e) {
		let type = e.detail.index==0?1:2
		this.setData({
			type:type,
			page:1,
			size:10,
			totalPage:1
		})
		this.getList()
	},
	getList(){
		app.indexApi.noticeLists({
			page:this.data.page,
			size:10,
			type:this.data.type
		}).then(res => {
			if (res.code == 0) {
				let _data = res.data;
				_data.map((item) => {
					
				});
				let list = []
				//分页
				if (_data.length == 0) {
					this.setData({
						totalPage:0,
					})
				}
				if (this.data.page > 1) {
					list = list.concat(_data);
				} else {
					list = _data;
				}
				this.setData({
					dataList:list,
				})
			}
		})
	},
	pageToView(e) {
		let id = e.currentTarget.dataset.id
		console.log(id)
		wx.navigateTo({
			url: "/pages/newsList/view?id=" + id
		})
	},
	onReachBottom() {
		let page = this.data.page
		if (this.data.totalPage == 0) {
			wx.showToast({
				title: '没有更多了···',
				icon: 'none'
			})
			return;
		}
		page++
		this.setData({
			page:page,
		})
		this.getList();
	},
})